# -*- coding:utf-8 -*-
# python 2.7
# author: zyh

from multiprocessing.dummy import Pool as ThreadPool
import time


# 计时函数
def timer(func):
    def _timer(*args,**kw):
        begin=time.time()
        rs=func(*args,**kw)
        end=time.time()
        print u"函数 %s 耗时 %ds\n" %(func.__name__,end-begin)
        return rs
    return _timer

# 耗时操作
def test(s):
    time.sleep(0.1)

class R:
    def __init__(self,l):
        self.l = l
    @timer
    def run1(self):
        pool = ThreadPool(10)
        pool.map(test,self.l)
        pool.close()  
        pool.join()

    @timer
    def run2(self):
        for each in self.l:
            test(each)


if __name__=="__main__":
    l = [x for x in range(1,100)]
    r = R(l)
    print "="*50
    print u"多进程"
    r.run1()
    print "="*50
    print u"顺序执行"
    r.run2()
    raw_input("按任意键继续...".decode("utf-8").encode("gbk"))

